package cn.gson.crm.controller;


import cn.gson.crm.model.pojos.*;
import cn.gson.crm.model.service.ContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.persistence.criteria.CriteriaBuilder;
import javax.servlet.http.HttpSession;
import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.*;


@Controller
@RequestMapping("/ControllerContract")
public class ControllerContract {
    @Autowired
    ContractService contractService;
    //查询当前登录人的合同
    @RequestMapping("/ContractMethod")
    @ResponseBody
    public Map<String,Object> ContractMethod(HttpSession session,Integer oursingner,Integer yid,String dept,Integer page,Integer size,String jinnian,String qunian,String qiannian){
        return   contractService.seleAll2emp(session,oursingner,yid,dept,page,size,jinnian,qunian,qiannian);
    }
    //按条件查询合同记录
    @RequestMapping("/ContractWhereMethod")
    @ResponseBody
    public Map<String,Object> ContractMethod2(HttpSession session,Integer oursingner,String condition,Integer page,Integer size){

        return   contractService.selectContractWhere(session,oursingner,condition,page,size);
    }

    //条件查询客户签约人
    @RequestMapping("/selectLinkman")
    @ResponseBody
    public List<Linkman> ContractMethod3(Integer cid){
        return   contractService.selectlinkman(cid);
    }
    //根据客户查询最新报价
    @RequestMapping("/selectbaojia")
    @ResponseBody
    public List<Customer>  ContractMethod4(Integer cid){
        return contractService.selectbaojia(cid);
    }
    //新增合同
    @RequestMapping("/saveController")
    @ResponseBody
    public void  ContractMethod5(HttpSession session,@RequestBody Contract contract){
        System.err.println(contract);
        contractService.saveContract(session,contract);
        contractService.updatxs(contract.getContractId(), (int) contract.getSales2().getSalesId());
    }
    //根据客户查询所有没有签合同的销售机会
    @RequestMapping("/selectsale")
    @ResponseBody
    public List<Sales>  ContractMethod6(Integer sid){
      return contractService.selectslase(sid);
    }
    //根据合同状态查询合同记录
    @RequestMapping("/selectzhuntai")
    @ResponseBody
    public Map<String,Object> ContractMethod7(HttpSession session,Integer oursingner,String zhuntai,Integer page,Integer size){
        return   contractService.selectzhutai(session,oursingner,zhuntai,page,size);
    }
    //修改查询报价和审批人
    @RequestMapping("/selectxiuxiang")
    @ResponseBody
    public Map<String,Object> ContractMethod8(Integer sid,Integer cid){
        return   contractService.selectxiuxiang(sid,cid);
    }
    //高级查询（多条件查询）
    @RequestMapping("/gaojiselect")
    @ResponseBody
    public Map<String,Object> ContractMethod9(HttpSession session,Integer oursingner, Integer condition1, String condition2, String condition3, String condition4, String condition5, String condition6, Integer page, Integer size){
        return   contractService.gaojiselect(session,oursingner,condition1,condition2,condition3,condition4,condition5,condition6,page,size);
    }
    //统计合同数量()
    @RequestMapping("/selectcontract")
    @ResponseBody
    public List<Shuliang> selectContrant(){
            return contractService.selectContrant();

    }
}
